package cn.aitrox.ry.service.image.bean;

import cn.aitrox.ry.bean.RespResult;
import cn.aitrox.ry.enumtype.RespCodeEnum;
import cn.aitrox.ry.service.config.enumtype.ImageTransferModeEnum;
import cn.aitrox.ry.service.image.entity.ImageTransferItemEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ImageTransferHandlerDelegate {

    @Autowired
    private VideoFrameExtractTransferHandler videoFrameExtractTransferHandler;

    public RespResult handler(ImageTransferItemEntity itemEntity) {
        ImageTransferModeEnum modeEnum = ImageTransferModeEnum.getEnum(itemEntity.getMode());
        if (null == modeEnum) {
            return RespResult.secByError(RespCodeEnum.PARAM_ERROR.getCode(), "不支持的转换模式: " + itemEntity.getMode());
        }
        ImageTransferHandler imageTransferHandler = null;
        switch (modeEnum) {
            case VIDEO_FRAME_EXTRACT:
                imageTransferHandler = videoFrameExtractTransferHandler;
                break;
            default:
                break;
        }
        if (null == imageTransferHandler) {
            return RespResult.secByError(RespCodeEnum.PARAM_ERROR.getCode(), "不支持的转换模式: " + itemEntity.getMode());
        }
        return imageTransferHandler.handler(itemEntity);
    }

}
